import logging
import os
from datetime import datetime

from configs import app_config


def get_logger():
    # 创建logs目录(如果不存在)
    log_dir = "logs"
    os.makedirs(log_dir, exist_ok=True)

    # 设置日志文件名(使用当前日期)
    log_file = os.path.join(
        log_dir,
        f"{datetime.now().strftime('%Y-%m-%d_%H')}.log",
    )

    # 创建一个logger实例
    logger = logging.getLogger("dianshang")

    # 防止日志传播到父logger
    logger.propagate = False

    # 重新配置logger，只处理您的应用程序日志
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s"
    )
    file_handler = logging.FileHandler(log_file)

    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)
    # logger.addHandler(logging.StreamHandler())
    return logger


logger = get_logger()

import os
print(os.getcwd())